{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ae203e78",
   "metadata": {},
   "source": [
    "# 1. 创建Flask最小应用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08258e2e",
   "metadata": {},
   "source": [
    "> 1. 传递一个文本到指定的路由URL界面\n",
    "> 2. 传递一个HTML的文本信息到指定路由URL界面\n",
    ">> 1. 思考：如果\"return html的代码，会显得HTML代码很多，且写在了PYTHON文件当中；\n",
    ">> 2. 思考：如果前（HTML）后（PYTHON）端可以分开两个文件（前后端分离）就比较好了；\n",
    ">> 3. 结论：使用render_template 方法实现前后端分离"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5717c106",
   "metadata": {},
   "outputs": [],
   "source": [
    "from flask import Flask\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "    return 'Hello, World!'\n",
    "\n",
    "@app.route('/index')\n",
    "def index():\n",
    "    return '<h1 >这是我的Python期末项目</h1>'\n",
    "\n",
    "\n",
    "app.run()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d0e8c5a",
   "metadata": {},
   "source": [
    "# 2. 创建Flask应用，实现静态页面的开发"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62d36223",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: This is a development server. Do not use it in a production deployment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:05] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:05] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:05] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:05] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:05] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:06] \"\u001b[37mGET /smart_app HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:06] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:06] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:06] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:06] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:29] \"\u001b[37mPOST /search HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:29] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:29] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:29] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:29] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#4ebbdf\n",
      "#f2a6a6\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [25/Dec/2023 20:27:50] \"\u001b[37mPOST /search HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:50] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:50] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:50] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:50] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#e2b1b1\n",
      "#ecfb79\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [25/Dec/2023 20:27:57] \"\u001b[37mPOST /search HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:57] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:57] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:57] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:27:57] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#e65c5c\n",
      "#db9be4\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "127.0.0.1 - - [25/Dec/2023 20:36:07] \"\u001b[37mPOST /search HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:36:07] \"\u001b[33mGET /assets/css/ie10-viewport-bug-workaround.css HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:36:07] \"\u001b[33mGET /assets/js/ie-emulation-modes-warning.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:36:07] \"\u001b[33mGET /dist/js/bootstrap.min.js HTTP/1.1\u001b[0m\" 404 -\n",
      "127.0.0.1 - - [25/Dec/2023 20:36:07] \"\u001b[33mGET /assets/js/ie10-viewport-bug-workaround.js HTTP/1.1\u001b[0m\" 404 -\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#dd9292\n",
      "#86fec6\n"
     ]
    }
   ],
   "source": [
    "from flask import Flask\n",
    "from flask import render_template,request\n",
    "app = Flask(__name__)\n",
    "\n",
    "@app.route('/')\n",
    "def hello_world():\n",
    "    return render_template('index.html')\n",
    "\n",
    "@app.route('/entry')\n",
    "def entry():\n",
    "    return render_template('entry.html')\n",
    "\n",
    "@app.route('/introduction')\n",
    "def introduction():\n",
    "    return render_template('introduction.html')\n",
    "\n",
    "@app.route('/contact')\n",
    "def contact():\n",
    "    return render_template('contact.html')\n",
    "\n",
    "@app.route('/smart_app')\n",
    "def smart_app():\n",
    "    return render_template('app.html')\n",
    "\n",
    "@app.route('/search',methods=['POST'])\n",
    "def search():\n",
    "    print(request.form['inputcolor_up'])\n",
    "    print(request.form['inputcolor_down'])\n",
    "    return render_template('app.html',\n",
    "                           bgcolor_up = request.form['inputcolor_up'],\n",
    "                           bgcolor_down = request.form['inputcolor_down'],)\n",
    "\n",
    "app.run()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "309f8d2a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
